<template>
  <div class="login">
    <div class="box">
      <section class="images">
        <p>
          <img src="../assets/logo.png" alt="" />
        </p>
      </section>
      <section class="form">
        <el-form :model="obj" :rules="rules" ref="form">
          <el-form-item prop="uname">
            <el-input
              placeholder="请输入用户名"
              prefix-icon="el-icon-user"
              v-model="obj.uname"
            >
            </el-input>
          </el-form-item>
          <el-form-item prop="psd">
            <el-input
              placeholder="请输入密码"
              prefix-icon="el-icon-lock"
              type="password"
              v-model="obj.psd"
            >
            </el-input>
          </el-form-item>
        </el-form>
        <p>
          <el-button type="primary" @click="get">登录</el-button>
          <el-button type="info" @click="chong">重置</el-button>
        </p>
      </section>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      obj: {
        uname: "admin",
        psd: "123456",
      },
      rules: {
        uname: [{ required: true, message: "请输入用户名", trigger: "blur" }],
        psd: [
          { required: true, message: "请输入活动名称", trigger: "blur" },
          {
            min: 6,
            max: 16,
            message: "长度在 6 到 16 个字符",
            trigger: "blur",
          },
        ],
      },
    };
  },
  methods: {
    get() {
      this.$refs.form.validate(async (res) => {
        if (res) {
          var { data } = await this.$http.post("/login", {
            username: this.obj.uname,
            password: this.obj.psd,
          });
          console.log(data);
          if (data.meta.status == 200) {
            sessionStorage.setItem('list', JSON.stringify(data.data))
            this.$message.success('登陆成功')
            this.$router.push("/home");
          }
        } else {
          return false;
        }
      });
    },
    chong() {
      this.$refs.form.resetFields();
    },
  },
};
</script>

<style lang="scss" scoped>
.login {
  width: 100%;
  height: 100%;
  background-color: aqua;
  .box {
    width: 450px;
    height: 304px;
    background-color: #fff;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    box-shadow: 0 0 10px #ddd;
    border-radius: 3px;
  }
  .images {
    width: 130px;
    height: 130px;
    padding: 10px;
    border: 1px solid #efefef;
    border-radius: 50%;
    background-color: #fff;
    position: absolute;
    left: 50%;
    transform: translate(-50%, -50%);
    box-shadow: 0 0 10px #ddd;
    img {
      width: 100%;
      height: 100%;
      border-radius: 50%;
      background-color: #efefef;
    }
  }
  .form {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    padding: 0 20px;
    box-sizing: border-box;
    p {
      display: flex;
      justify-content: flex-end;
      padding-bottom: 20px;
    }
  }
}
</style>